
import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;

 public class Reduce extends MapReduceBase implements Reducer<Text, Text, Text, Text> {
	
		  @Override
		public void reduce(Text key, Iterator<Text> values, OutputCollector<Text, Text> output, Reporter reporter) throws IOException {
			  System.err.println("Reduce Start");
			  LinkedList<Integer> l = new LinkedList<Integer>();
			  while(values.hasNext())
			  {
				  Text val = values.next();
				  if(val.toString().compareTo("")==0){}
				  else l.add(Integer.parseInt(val.toString()));
			  }
			  Collections.sort(l);
			  output.collect(new Text(key),new Text(l.toString().replaceAll("[\\[\\]\\s]","")));
			  System.err.println("Reduce Completed");
		}
	  }